package cn.itcast.activiti.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.TaskService;

import cn.itcast.activiti.common.ProcessEngineUtils;

/**
 * 领取任务控制器
 * @author LEE.SIU.WAH
 * @email lixiaohua7@163.com
 * @date 2016年5月7日 上午11:29:39
 * @version 1.0
 */
@WebServlet("/claimTask.action")
public class ClaimTaskServlet extends HttpServlet{

	private static final long serialVersionUID = 9160861029113776868L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
    //获取任务id
	String taskId=request.getParameter("taskId");
	//获取Session中的用户
	String userId=(String) request.getSession().getAttribute("username");
	
	//获取流程引擎
	ProcessEngine processEngine=ProcessEngineUtils.getProcessEngine();
	//获取任务服务
	TaskService taskService=processEngine.getTaskService();
	//领取任务
	taskService.claim(taskId, userId);
	
	response.sendRedirect(request.getContextPath()+"/queryUserTask.action");
	
	
	}
	
}
